package com.example.mylibrary;

import static android.content.ContentValues.TAG;

import android.app.Instrumentation;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class BarterRelease {

    public static UiDevice device;
    public static Instrumentation instrumentation;

    @Before
    public void first() throws InterruptedException {
        Log.i(TAG, "连接设备");
        instrumentation =
                InstrumentationRegistry.getInstrumentation();
        device = UiDevice.getInstance(instrumentation);
        int width = device.getDisplayWidth();
        int height = device.getDisplayHeight();
        device.pressHome();
        Thread.sleep(2000);
        device.swipe(width - 10, height / 2, 50, height / 2, 10);
        Thread.sleep(2000);
        UiObject2 barter = device.findObject(By.text("Barter"));
        barter.click();
        Thread.sleep(3000);
    }

    //    发布闲置-信息填写完全-发布学习用品类型成功
    @Test
    private void Release8() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);
//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }

    //发布闲置-不添加照片-成功发布学习用品商品
    @Test
    private void Release9() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);
//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);

    }

    //发布闲置-无法添加照片
    @Test
    private void Release10() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//添加照片失败，无反应
    }

    //发布闲置-添加照片成功
    @Test
    private void Release11() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//添加照片成功，成功显示图片
    }

    //发布闲置-不输入标题发布
    @Test
    private void Release12() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);

//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }

    //发布闲置-不选择类别发布
    @Test
    private void Release13() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);

//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }

    //    发布闲置-不输入价格发布
    @Test
    private void Release14() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);
//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }

    //    发布闲置-不输入联系方式发布
    @Test
    private void Release15() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);
//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }

    //    发布闲置-不添加描述发布
    @Test
    private void Release16() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);
//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);

//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }

    @After
    public static void tearDown() {
        device.pressBack();
    }
}


